<template>
  <div class="article-item__container">
    <!-- 遮罩层 -->
    <van-action-sheet
      v-model="show"
      :actions="actions"
      :cancel-text="bottom_text"
      close-on-click-action
      @cancel="onCancel"
      @select="onSelect"
      @close="onClose"
      get-container="body"
    />
    <van-cell>
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ item.title }}</span>
          <!-- 单图 -->
          <!-- <img
            v-if="item.cover.type == 1"
            :src="item.cover.images[0]"
            class="thumb"
            alt=""
          /> -->
          <van-image
            v-if="item.cover.type == 1"
            :src="item.cover.images[0]"
            class="thumb"
          >
            <template v-slot:error>加载失败</template>
          </van-image>
        </div>
        <!-- 三图 -->
        <div class="thumb-box" v-if="item.cover.type == 3">
          <!-- <img
            v-for="(i, index) in item.cover.images"
            :key="index"
            :src="i"
            alt=""
            class="thumb"
          /> -->
          <van-image
            v-for="(i, index) in item.cover.images"
            :key="index"
            :src="i"
            class="thumb"
          >
            <template v-slot:error>加载失败</template>
          </van-image>
        </div>
      </template>
      <!-- label区域 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ item.aut_name }}</span>
            <span>{{ item.comm_count }}评论</span>
            <!-- <span>{{ setTimeAgo(item.pubdate) }}</span> -->
            <!-- 使用预处理 -->
            <span>{{ item.pubdate }}</span>
          </div>
          <!-- 反馈组件  叉叉-->
          <van-icon
            name="cross"
            class="cross"
            @click="show = true"
            v-if="isShow == true"
          />
        </div>
      </template>
    </van-cell>
  </div>
</template>

<script>
import moment from "moment";

import { firstActions, secondActions } from "@/api/reports.js";

export default {
  name: "ArticleItem",
  props: {
    item: Object,
    isShow: {
      type: Boolean,
      default: true,
    },
    // 例如首页的地方我不想再去动了, 首页肯定没穿isShow值进来, 所以首页需要显示
  },
  data() {
    return {
      atricle: [],

      show: false,
      actions: firstActions,
      bottom_text: "取消",
    };
  },
  created() {
    this.item.pubdate = this.setTimeAgo(this.item.pubdate);
  },
  methods: {
    setTimeAgo(time) {
      moment.locale("zh-cn");
      return moment(time).fromNow();
    },
    onClose() {
      this.actions = firstActions;
      this.bottom_text = "取消";
    },
    onCancel() {
      // Toast("取消");
      if (this.bottom_text == "返回") {
        this.actions = firstActions;
        this.show = true;
        this.bottom_text = "取消";
      }
    },
    // onSelect(item) {
    onSelect(action, item) {
      console.log(action);
      // console.log(item);
      if (action.name == "反馈垃圾内容" && item == 1) {
        this.show = true;
        this.actions = secondActions;
        this.bottom_text = "返回";
      } else if (action.name == "不感兴趣") {
        this.show = false;
        this.$emit("dislikearticle", this.item.art_id);
      } else {
        this.$emit("reportArticle", this.item.art_id, action.value);
        this.show = false;
      }
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起

      // Toast(item.name);
    },
  },
};
</script>

<style lang="less" scoped>
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
// 关闭按钮
.cross {
  position: absolute;
  bottom: 5px;
  right: 5px;
}

// 图片样式 矩形比例0-618
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

// 三图 图片容器
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
